package java12;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

public class BufferedReaderTestTest {

	@Test
	public void testPrintWrite() {
       String FILENAME = "test.txt";
		
		//write using PrintWriter
		
		PrintWriter pw=null;
		try {
			pw = new PrintWriter(FILENAME);
			for(int i = 0;i<10000000;i++){//写入1千万行
			pw.println(new Random().nextInt(100000));
		}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally{
			pw.close();
		}
	}
	
	@Test
	public void testScanner() {
       String FILENAME = "test.txt";
	Scanner scanner=null;
	try {
		scanner = new Scanner(new File(FILENAME));
		while(scanner.hasNextLine()){//只是读出每一行，不做任何处理
			scanner.nextLine();
		}
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}finally{
		scanner.close();
	}

	}
	
	@Test
	public void testBufferedReader() {
		 String FILENAME = "test.txt";
		BufferedReader br = null;
		try {
			 br = new BufferedReader(new FileReader(new File(FILENAME)));
			while(br.readLine()!=null){};//只是读出，不进行任何处理
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
}
